package com.study.clothes.controller;


import com.study.clothes.pojo.RespBean;
import com.study.clothes.pojo.User;
import com.study.clothes.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Jiayu.Yang
 * @since 2021-12-29
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private IUserService iUserService;
    @GetMapping("/")
    public List<User> userList(){
        return iUserService.list();
    }
    @PostMapping("/")
    public RespBean add(User user){
        if (iUserService.save(user)){
            return RespBean.success("添加成功");
        }
        return RespBean.error("添加失败");

    }
    @PutMapping("/")
    public RespBean update(User user){
        if (iUserService.updateById(user)) {
            return RespBean.success("修改成功");
        }
        return RespBean.error("修改失败");
    }
    @DeleteMapping("/{id}")
    public RespBean deleteOrder(@PathVariable Integer id){
        if (iUserService.removeById(id)) {
            return RespBean.success("删除成功");
        }
        return RespBean.error("删除失败");

    }
}
